// 寄生组合式继承
// 基本思想：通过借用函数来继承属性，通过原型链的混成形式来继承方法

function inheritProperty(subType, superType) {
  var prototype = Object.create(superType.prototype); //创建对象
  prototype.constructor = subType; // 增强对象
  subType.prototype = prototype;
}

function SuperType(name) {
  this.name = name;
  this.colors = ["red", "blue", "green"];
}
SuperType.prototype.sayName = function() {
  console.log(this.name);
};

function SubType(name, age) {
  SuperType.call(this, name);
  this.age = age;
}
inheritProperty(SubType, SuperType);
SubType.prototype.sayAge = function() {
  console.log(this.age);
};

var instance1 = new SubType('Andy1', 11);
var instance2 = new SubType('Andy2', 22);
instance1.sayAge();
instance1.sayName();
instance2.sayAge();
instance2.sayName();
